package com.heima.leadnews.wemedia.controller;

import com.heima.leadnews.wemedia.service.WmMaterialService;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmMaterialDTO;
import com.jlefebure.spring.boot.minio.MinioException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 自媒体图文素材信息表 前端控制器
 *
 * @since 2023-06-03
 */
@RestController
@RequestMapping("/api/v1/material")
@Slf4j
@Api("素材管理相关接口")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 上传图片
     *
     * @param multipartFile
     * @return
     */
    @ApiOperation("上传图片")
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) throws MinioException, IOException {
        log.info("上传图片,参数为{}", multipartFile);
        return wmMaterialService.uploadPicture(multipartFile);
    }

    /**
     * 分页查询我的素材
     *
     * @param wmMaterialDTO
     * @return
     */
    @ApiOperation("分页查询我的素材")
    @PostMapping("/list")
    public ResponseResult pager(@RequestBody WmMaterialDTO wmMaterialDTO) {
        log.info("分页查询我的素材,参数为{}", wmMaterialDTO);

        //接收前端传递的参数
        //调用service
        //响应结果
        return wmMaterialService.pager(wmMaterialDTO);
    }

    /**
     * 收藏素材、取消素材
     *
     * @param
     * @return
     */
    @ApiOperation("收藏素材")
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Integer id) {
        log.info("收藏素材,参数为{}", id);
        //接收前端传递的参数
        //调用service
        //响应结果
        return wmMaterialService.collect(id);
    }

    /**
     * 删除素材
     *
     * @param
     * @return
     */
    @ApiOperation("删除素材")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable Integer id) throws MinioException {
        log.info("删除素材,参数为{}", id);
        //接收前端传递的参数
        //调用service
        //响应结果
        return wmMaterialService.delPicture(id);
    }
}
